package com.ohc.leetcode.数组.repect;

/**
 * 2022年5月4日14:36:51
 */
public class 移除元素02 {
    public static int removeElement(int[] nums, int val) {
        int left = 0;
        int right = 0;
        int length = nums.length;
        int temp = 0;
        while (right < length) {
            if (nums[right] != val) {
                nums[left] = nums[right];
                left++;
                right++;
                length--;
            } else {
                right++;
            }

        }
        for (int i = 0; i < length; i++) {
            System.out.println("nums[i] = " + nums[i]);
        }
        return 0;
//        1 2 3   2
//       1 3 2

    }

    public static void main(String[] args) {
        int[] nums = new int[]{3, 2, 2, 3};
        int i = removeElement(nums, 2);
//        System.out.println("i = " + i);
    }
}
